package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.InvestmentCountData;
import org.example.mapper.InvestmentCountDataMapper;
import org.example.service.InvestmentCountDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 投资收益率数据表Service实现类
 */
@Service
public class InvestmentCountDataServiceImpl extends ServiceImpl<InvestmentCountDataMapper, InvestmentCountData>
        implements InvestmentCountDataService {

    @Override
    public int batchSave(List<InvestmentCountData> dataList) {
        if (dataList == null || dataList.isEmpty()) {
            return 0;
        }

        // 使用MyBatis Plus的批量保存
        return this.saveBatch(dataList) ? dataList.size() : 0;
    }

    @Override
    public List<InvestmentCountData> getByCategoryType(String categoryType) {
        LambdaQueryWrapper<InvestmentCountData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InvestmentCountData::getCategoryType, categoryType)
               .orderByAsc(InvestmentCountData::getPeriodDate);
        return this.list(wrapper);
    }

    @Override
    public int clearByCategoryType(String categoryType) {
        LambdaQueryWrapper<InvestmentCountData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InvestmentCountData::getCategoryType, categoryType);
        return this.baseMapper.delete(wrapper);
    }
}
